#include "CyNetAccelerometer.h"
#include <math.h>

#define PACKET_SIZE 24;

CyNetAccelerometer::CyNetAccelerometer(void)
{
}


CyNetAccelerometer::~CyNetAccelerometer(void)
{
}

int CyNetAccelerometer::GetSize() const
{
	return PACKET_SIZE;
}

int CyNetAccelerometer::GetStream(char* buffer, int size) const
{
	return PACKET_SIZE;
}

CyNetObject& CyNetAccelerometer::FromStream(const char* buffer)
{
	// read x
	_x = *reinterpret_cast<const float*>(buffer + 12);

	// read y
	_y = *reinterpret_cast<const float*>(buffer + 16);

	// read z
	_z = *reinterpret_cast<const float*>(buffer + 20);

	return *this;
}

CyNetObjectEnum CyNetAccelerometer::GetType() const
{
	return CyNetObjectEnum::ACCELEROMETER;
}

float CyNetAccelerometer::Magnitude()
{
	return sqrt(_x * _x + _y * _y + _z * _z);
}